<%@ page language="java" import="java.util.*, java.io.*, 
	org.apache.ibatis.io.*,
	org.apache.ibatis.session.*,
	static com.expmanage.actions.utils.DatabaseConfigure.*,
	com.expmanage.models.*" contentType="text/html;charset=UTF-8" 
	pageEncoding="UTF-8" %>
<%@taglib uri="/struts-tags" prefix="s"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    <% request.setCharacterEncoding("UTF-8");%>
    <title>教师信息</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
</head>
  <body>
  	<script type="text/javascript"> 
		function checkValidate() {
			var tname = document.getElementById("name");
			var email = document.getElementById("email");
			var password = document.getElementById("password");
			var password_confirm = document.getElementById("password_confirm");
			if (tname.value == "" || tname.value == null) {
				window.alert("姓名不能为空！！！");
				return false;
			}
			if (email.value == "" || email.value == null) {
				window.alert("邮箱不能为空！！！");
				return false;
			}
			if (password.value == "" || password.value == null) {
				window.alert("密码不能为空！！！");
				return false;
			}
			if (password.value == "" || password.value == null) {
				window.alert("密码不能为空！！！");
				return false;
			}
			if (password_confirm.value != password.value) {
				window.alert("密码确认错误！！！");
				return false;
			}
		}
	</script>
	
	  	<%
		if (session.getAttribute("user") == null
				|| !session.getAttribute("user").equals("root_manager")
				|| !session.getAttribute("role").equals("manager")) {
		%>
		<script language="javascript">
			alert("需要登录");
			window.open("index.jsp", "_self");
		</script>
		<%
		}
		%>
  
  	<%!
  	void loadTeachers(JspWriter out){
		if(sqlSessionFactory!=null){
			SqlSession sqlsession = sqlSessionFactory.openSession();
       		try {
           		TeacherMapper mapper = sqlsession.getMapper(TeacherMapper.class);
           		List<Teacher> teachers = mapper.selectTeacherAll();
           		int i = 0; 
           		for (Teacher teacher : teachers) {
           			int tid = teacher.getTid();
               		out.print("<tr><td>"+ tid + "</td>"
               			+ "<td>"+ teacher.getName() + "</td>" 
               			+ "<td>"+ teacher.getEmail() + "</td>" 
               			+ "<td><input type=\"checkbox\" value=\"" +
               			+ tid + "\" name=\"sid_del_list\"></td>" +
               			"</td></tr>");
            	}
        	} catch(Throwable e){
        		e.printStackTrace();
       		} finally {
           		sqlsession.close();
       		}
       	}else{
       		//输出错误
      	}
  	}
  	%>
  	<form id="forms" name="forms" action="checkTeachers.action"
		method="POST">
		<table>
    	<tr><td>教师信息：</td><td><input type="submit" value="提交教师信息删除名单"/></td></tr>
    	</table>
    	<table border=1>
    	<tr><td>Tid</td><td>Name</td><td>邮箱</td><td>删除</td>
    	</tr>
    	<%
		if (session.getAttribute("user").equals("root_manager")) {
			loadTeachers(out);
		}
		%>
		</table>
	</form>

	<form id="form_add" name="form_add" action="tRegist.action"
		method="POST">
		<table><tr><td>教师姓名</td><td>邮箱</td><td>初始密码</td><td>密码确认</td><td>提交</td></tr>
		<tr><td><input type="text" name="name" size="20" id="name"
						maxlength="20" /></td>
			<td><input type="text" name="email" size="20" id="email"
						maxlength="50" /></td>
			<td><input type="password" name="password" size="16" id="password"
						maxlength="16" /></td>
			<td><input type="password" name="password_confirm" size="16" id="password_confirm"
						maxlength="16" /></td>
			<td><input type="submit" name="submit" value="注册" 
				onclick="return checkValidate()" /></td>
			</tr>
		</table>
	</form>
  </body>
</html>
